<?php

define('SUFFIX_CONTROLLER', 'Controller');
define('SUFFIX_SERVICE', 'Service');
define('SUFFIX_DOMAIN', '_Domain');
define('SUFFIX_MANAGER', 'Manager');
define('SUFFIX_UI', 'UI');
define('PREFIX_BASE', 'Base');

function __autoload($classname) {

	if (!class_exists($classname)) {

		$folder = CORE;

		if (strstr($classname, SUFFIX_CONTROLLER)) {
			$folder = CONTROLLER;
		}

		if (strstr($classname, SUFFIX_DOMAIN)) {
			$classname = str_replace(SUFFIX_DOMAIN, '', $classname);
			
			$folder = MODEL_DOMAIN;
		}
		
		if (strstr($classname, SUFFIX_SERVICE)) {
			$folder = MODEL_SERVICE;
		}
		
		if (strstr($classname, SUFFIX_MANAGER)) {
			$folder = MODEL_PERSITENCE;
		}
		
		if (strstr($classname, SUFFIX_UI)) {
			$folder = UI_CLASSES;
		}

		if (strstr($classname, PREFIX_BASE)) {
			$folder = CORE;
		}

		$classname = lcfirst($classname);

		$classDirectory = $folder . '/' . $classname . EXT;

		require_once $classDirectory;
	}
}